package kr.hkit.powerjava.chapter22.submit2; 

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import kr.hkit.powerjava.chapter22.submit2.dao.DepartmentManagerImpl;
import kr.hkit.powerjava.chapter22.submit2.dao.StudentManagerImpl;
import kr.hkit.powerjava.chapter22.submit2.vo.Department;
import kr.hkit.powerjava.chapter22.submit2.vo.Student;

//dao, vo 따로 패키지 만듬
//오늘 하는거 진짜 중요합니다요!!! 다시리뷰

public class TestMain {
	public static void main(String[] args) { 
	/*	ArrayList<Student> stdList = new ArrayList<>();
		StudentManagerImpl sm = new StudentManagerImpl(stdList);
		
		//추가
		Student std1 = new Student(1, "김태희", 90, 90, 90);
		sm.addItem(std1);
		Student std2 = new Student(2, "제시카", 89, 79, 77);
		sm.addItem(std2);
		sm.addItem(new Student(3, "김주하", 80, 80, 80));
		sm.addItem(new Student(4, "이민정", 78, 79, 89));
		sm.addItem(std1);//중복가능.
		
		//삭제
		sm.delItem(std1); 
		sm.delItem(std2);
		
		//검색. //존재하는데도 null나옴. 이유는? equals 안해줘서.....
		Student searchItem = new Student(1,"김태희"); //학번이나 이름중 하나라도 틀리면 안나옴 
		String result = sm.searchItem(searchItem)?"존재":"없음";//리턴타입이 스튜던트
		System.out.println(searchItem.getStdNum() + " : " + searchItem.getStdName() + " = " + result);
		
		//수정
		Student updateItem = new Student(1, "김태희", 91, 93, 94);
		sm.updateItem(updateItem);
	
		//출력
		sm.prnItems(); 
		System.out.println("총점순 정렬(내림차순)");
		Comparator<Student> totalCom = new Comparator<Student>() {
			@Override
			public int compare(Student o1, Student o2) {
				return (int) (o2.getTotal() - o1.getTotal());
			}
		};
		sm.prnItems(totalCom);
		
		
		System.out.println("이름순 정렬(오름차순)"); 
		Comparator<Student> com = new Comparator<Student>() {
			@Override
			public int compare(Student o1, Student o2) {
				return o1.getStdName().hashCode() - o2.getStdName().hashCode();
			}
		};
		sm.prnItems(com);
	
		
		System.out.println("국어점수 정렬(내림차순)"); 
		//이렇게 바로해도됨. 안드로이드에서 많이씀.
		sm.prnItems (new Comparator<Student>() { //무명클래스
			@Override
			public int compare(Student o1, Student o2) {
				return (int) (o2.getKor() - o1.getKor());
			}
		});

		
		for(Student std:stdList){
			System.out.println(std);
		}
		
		
		Collections.shuffle(stdList);
		System.out.println("반복자============");
		Student std = null;
		Iterator<Student> iterator = stdList.iterator();
		while(iterator.hasNext()) {
			std = iterator.next();
			System.out.println(std);
		}*/
		
		
		
		//////Department 테스트//////
		ArrayList<Department> deptList = new ArrayList<>();
		DepartmentManagerImpl dept = new DepartmentManagerImpl(deptList);
		
		//추가
		Department dept1 = new Department(10, "컴공", 1);
		dept.addItem(dept1);
		dept.addItem(new Department(20, "국통", 3));
		dept.addItem(new Department(30, "경영", 4));
		dept.addItem(new Department(40, "경제", 5));
		
		//삭제
		dept.delItem(dept1); 
		
		//검색. //equals해줘야함 
		/*
		Department searchItem = new Department(10, "컴공");
		String result = dept.searchItem(searchItem)? "존재" : "없음";
		System.out.println(searchItem.getDeptNo() + " : " + searchItem.getDeptName() + " = " +result);
		*/
		
		//검색2
		Map<Integer, Department> map = new HashMap<>();
		map.put(1, new Department(50, "국문", 10) );
		map.put(2, new Department(60, "영문", 11) );
		map.put(3, new Department(70, "독문", 13) );
		System.out.println(map);
//		map.remove(1); //삭제는 remove
		
		for (Map.Entry<Integer, Department> d : map.entrySet()){//entrySet. d의 목록 가져오기
			int key = d.getKey();
			Department value = d.getValue();
			System.out.println("key = " + key + ", Value = " + value); 
		} System.out.println();
		
		//학과명으로도 해보기 
		
		
		//수정
		Department updateItem = new Department(20, "국통", 6);
		dept.updateItem(updateItem);
		
		
		//출력-정렬해서. 학과번호순/학과명순/층순
		dept.prnItems();
		System.out.println("학과번호순 정렬");
		Comparator<Department> deptNum = new Comparator<Department>() {
			@Override
			public int compare(Department o1, Department o2) {
				return o1.getDeptNo() - o2.getDeptNo();
			}
		}; dept.prnItems(deptNum);
		

		System.out.println("학과명순 정렬");
		dept.prnItems(new Comparator<Department>() {
			@Override
			public int compare(Department o1, Department o2) {
				return o1.getDeptName().hashCode() - o2.getDeptName().hashCode();
			}
		}); 
		

		System.out.println("층순 정렬");
		dept.prnItems(new Comparator<Department>() {
			@Override
			public int compare(Department o1, Department o2) {
				return o1.getFloor() - o2.getFloor();
			}
		}); 
		
	}	

}
